<%@page import="java.util.*"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="org.json.simple.JSONObject"%>
<%@ page import="org.json.simple.JSONArray"%>
<%@ page import="java.net.URLEncoder"%>

<%
	
	String memail1=request.getParameter("memail1");
	//String mcode="M1";
	//String fmcode="M1";
	//String omcode="M2";
	
	
	
	String url="jdbc:oracle:thin:@192.168.0.18:1521:orcl";
	String user="book";
	String password="book";
	
	String sql1=null;
	String sql5=null;
	
	String mcode="";
	String heartcount="";
	
	Connection conn=null;
	ResultSet rs1=null;
	ResultSet rs5=null;
	PreparedStatement stmt1=null;
	PreparedStatement stmt5=null;
	
	
	try{
		Class.forName("oracle.jdbc.driver.OracleDriver");
		//out.println("드라이버 로딩 성공");
		conn=DriverManager.getConnection(url, user, password);
		//out.println("접속 성공");
		
		sql1="select mcode from member where memail1=?";
		sql5="SELECT MCODE, SUM(HPLUS)-SUM(HMINUS) as TOTAL FROM HEART WHERE mcode in (select mcode from member where memail1=?) GROUP BY ROLLUP(MCODE)";
		
		stmt1=conn.prepareStatement(sql1);

		stmt1.setString(1, memail1);
		rs1 = stmt1.executeQuery();
		
		stmt5=conn.prepareStatement(sql5);
		
		stmt5.setString(1, memail1);
		rs5 = stmt5.executeQuery();
		
		while(rs1.next()){
			mcode=rs1.getString("mcode");
		}

		while(rs5.next()){
			heartcount=rs5.getString("total");
		}
		
	}catch(Exception e){
		out.println("접속 실패");
		e.printStackTrace();
	}finally{
		if(stmt1!=null) stmt1.close();
		if(stmt5!=null) stmt5.close();
		if(conn!=null) conn.close();
	}
	
%>
{"mcode" : "<%= mcode %>",
"heartcount" : "<%= heartcount %>"}
